package learning.chatRoom;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JTextArea;

public class ReadMsgThread extends Thread {
	private SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
	private Socket s;
	private JTextArea jta_msg;

	public ReadMsgThread(Socket s, JTextArea jta_msg) {
		this.s = s;
		this.jta_msg = jta_msg;
	}

	@Override
	public void run() {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
			while (true) {
				String msg = br.readLine();
				jta_msg.append(msg+"\t"+sdf.format(new Date()));
				jta_msg.append("\n");
				// System.out.println(msg);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
